<template>
    <!-- 地址列表 -->
    <div class="addressList">
        <div v-if="list.length > 0">
            <van-address-list
                v-model="chosenAddressId"
                :list="list"
                default-tag-text="默认"
                @add="onAdd"
                @edit="onEdit"
                @select="onSelect"
            />
        </div>
        <van-contact-card v-else type="add" @click="onAdd" />
    </div>
</template>

<script>
import { Toast } from "vant"
import { reqAddressList } from "../../http/api"
export default {
    data() {
        return {
            chosenAddressId: '1',
            list: [],
        };
    },
    mounted() {
        reqAddressList({
            uid: JSON.parse(localStorage.getItem("isLogin")).uid,
        }).then((res) => {
            if (res.data.code == 200) {
                var list = res.data.list ? res.data.list : [];
                this.list = list.map((item) => {
                    return {
                        id: item.id,
                        name: item.username,
                        tel: item.userphone,
                        address: item.location + item.useraddress,
                        idDefault: item.status == 1,
                    }
                })
            }
        })
    },
    methods: {
        onAdd() {
            this.$router.push("/a-add")
        },
        onEdit(item, index) {
            this.$router.push("/a-add?id=" + item.id)
        },
        onSelect(item,index){
            this.$router.replace("/order?addressId="+item.id)
        }
    },

}
</script>

<style scoped lang="less">
@import url(../../less/index.less);
@import url(../../less/index.less);
</style>